﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="EVK_kanded_v1_paring", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(EVKKandedV1Paring))]
    public class EVKKandedV1ParingSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IEVKKandedV1Paring clazz;
        
        public EVKKandedV1ParingSerializer(IEVKKandedV1Paring clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("alguskpv");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.Alguskpv))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("loppkpv");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.Loppkpv))).ToString());
            Writer.WriteEndElement();
            if (clazz.Evkood!=null) {
                Writer.WriteStartElement("evkood");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.Evkood))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Syndmus!=null) {
                Writer.WriteStartElement("syndmus");
                Writer.WriteTypeAttribute("http://producers.arireg.xtee.riik.ee/producer/arireg", "x_evk_syndmus");
                Writer.WriteString(clazz.Syndmus.ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Keel!=null) {
                Writer.WriteStartElement("keel");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Keel))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="alguskpv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>EVK_kanded_v1_paring>alguskpv");
                }
                clazz.Alguskpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("alguskpv")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>EVK_kanded_v1_paring>alguskpv", Reader.LocalName);
            }
            if (Reader.LocalName=="loppkpv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>EVK_kanded_v1_paring>loppkpv");
                }
                clazz.Loppkpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("loppkpv")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>EVK_kanded_v1_paring>loppkpv", Reader.LocalName);
            }
            if (Reader.LocalName=="evkood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>EVK_kanded_v1_paring>evkood");
                }
                clazz.Evkood = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("evkood")).Value;
            }
            if (Reader.LocalName=="syndmus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>EVK_kanded_v1_paring>syndmus");
                }
                clazz.Syndmus = new global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.XEvkSyndmus(Reader.ReadElementString("syndmus"));
            }
            if (Reader.LocalName=="keel") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>EVK_kanded_v1_paring>keel");
                }
                clazz.Keel = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("keel")).Value;
            }
        }
    }
}
